# -*- coding: utf-8 -*-

from urllib import request
from urllib import parse

# 创建一个Request对象 //使用request对象
# req = request.Request('http://www.imooc.com')

# # 使用Request对象发送请求 
# response = request.urlopen(req)
# text = response.read()
# # text = parse.quote_from_bytes(text, safe='/')
# # text.replace("\xa9",'',100)
# # text = parse.unquote(text)
# # print(response.read())
# print(text)
# # print(parse.unquote('\xe4\xb8\x8b\xe8\xbd\xbd',encoding='utf-8'))

#发送post请求
# post_value = {
#     'keyword': '大数据', 
#     'pageCount': '1'}
# # 把dict对象转换为请求的url参数字符，并按照utf-8转换为字节 
# post_data = parse.urlencode(post_value).encode('utf-8')
# # 发送携带参数的POST请求 
# req = request.Request(
#     'http://www.iimedia.cn/do_search.jsp', data=post_data)
# response = request.urlopen(req)
# print(response.read())

#带参数的get
url = 'http://www.imooc.com/search/course' 
get_value = {'words': 'Python', } 
get_data = parse.urlencode(get_value) 
# 拼装后的URL就是http://www.imooc.com/search/course?words=Python 
req = request.Request(url + '?' + get_data) 
response = request.urlopen(req) 
print(response.read())
